#!/bin/bash
sed -i 's@https://labs.mysql.com/common/css/print-20190125.min.css@css/print-20190125.min.css@g' *.html
sed -i 's@https://labs.mysql.com/common/css/print-20190125.min.css@css/print-20190125.min.css@g' *.html
sed -v
sed -i 's@https://labs.mysql.com/common/css/main-20190125.min.css@css/main-20190125.min.css@g' *.html
sed -i 's@https://labs.mysql.com/common/css/docs-20190125.min.css@css/docs-20190125.min.css@g' *.html
sed -i 's@https://labs.mysql.com/common/js/site-20181120.min.js@js/site-20181120.min.js@g' *.html
sed -i 's@https://labs.mysql.com/common/js/metrics/s_code_remote.js@js/s_code_remote.js@g' *.html
sed -i 's@//consent.truste.com/notice?domain=mysql.com&c=teconsent&text=true&language=en@js/notice.js@g' *.html
sed -i 's@https://labs.mysql.com/common/themes/sakila/favicon.ico@favicon.ico@g' *.html
sed -i 's@onfocus=".*"@onfocus=""@g' *.html
sed -i 's@onblur=".*"@onblur=""@g' *.html
sed -i 's@action="/doc/search/"@action="/mysql-manual/search-page"@g' *.html
echo "" > js/notice.js

# es创建index
curl -X PUT \
  http://localhost:9200/mysql-manual

# es建立index-type
curl -X POST \
  'http://localhost:9200/mysql-manual/_mapping?pretty=' \
  -H 'Content-Type: application/json' \
  -d '{
    "properties": {
        "id": {
            "type": "integer"
        },
        "title": {
            "type": "text"
        },
        "filename": {
            "type": "text"
        },
        "content": {
            "type": "text"
        }
    }
}'

# es搜索示例
curl -X GET \
  http://localhost:9200/mysql-manual/_search \
  -H 'Content-Type: application/json' \
  -d '{
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "filename": {
                            "query": "alter",
                            "operator": "and"
                        }
                    }
                },
                {
                    "match": {
                        "content": {
                            "query": "alter",
                            "operator": "and"
                        }
                    }
                },
                {
                    "match": {
                        "title": {
                            "query": "alter",
                            "operator": "and"
                        }
                    }
                }
            ]
        }
    },
    "from": 1,
    "size": 5
}'
